<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" id="teacherForm">
<head>
    <title>虚机授权</title>
    <script type="text/javascript">
    var mainform;
    var viewType = "${viewType}";

    $(function (){
    
    	$("#dateF").ligerDateEditor();
    	$("#dateT").ligerDateEditor();
    	
        mainform=$("#mainform");
        
        mainform.ligerForm();
        
        if(viewType=="modify"){
			$("#id").attr("readonly", "readonly").removeAttr("validate");
        }
        
        //如果是详细试图,所有字段不可编辑
        if(viewType=="detail"){
        	$("input,select,textarea",mainform).attr("readonly", "readonly");
        }else{
            $.metadata.setType("attr", "validate");
            LG.validate(mainform);
        }
        
        //渲染按钮
        LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : save);

    });
   
    function save(){
    	//检查日期
    	var dateF = new Date($("#dateF").val().replace(/\-/g, "\/"));
    	var dateT = new Date($("#dateT").val().replace(/\-/g, "\/"));
    	if (dateT < dateF)
    	{
      		LG.tip("結束日期不可早于开始日期");
    		$("#dateT").focus();
    		return false;   		
    	}
    	
        LG.submitForm(mainform, function (result) {
        	if(typeof(result)=="string"){
        		result=eval("("+result+")");
        	}
            if (!result.success) {
                LG.showError('错误:' + data.message);
            }
            else { 
                LG.showSuccess('保存成功', function () { 
                   LG.callParent("clsList");
                });
            }
        });
    }
    
    function cancel(){
        var win = window.parent || window;
        if(win.dialog){
        	win.dialog.close();
        }
    }
 </script>
</head>

<body>
    <form name="mainform" method="post" id="mainform" action="${ctx}/qso/vmuser/save">
        <input type="hidden" name="viewType" value="${viewType}"/>
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 90%; margin-top:10px; margin-left:15px;">
            <tr>
                <td align="right" class="l-table-edit-td">虚机编号:</td>
                <td align="left" class="l-table-edit-td" colspan="4">
                	${command.id}
                	<input name="id" type="hidden" id="id" value="${command.id}" ltype="text" />
                </td>
                <td align="left"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td">授权人员:</td>
                <td align="left" class="l-table-edit-td" colspan="4">
                	<select style="width: 180px" name="userId" id="userId" ltype="select" validate="{required:true}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> >
                	 	<c:forEach items="${userList}" var="user">
                	 		<c:choose>
                	 			<c:when test="${command.user.userId eq user.userId}">
                	 				<option value="${user.userId}" selected="selected">${user.userNameC}</option>
                	 			</c:when>
                	 			<c:otherwise>
                	 				<option value="${user.userId}">${user.userNameC}</option>
                	 			</c:otherwise>
                	 		</c:choose>
                	 	</c:forEach>
                	 </select> 
                </td>
                <td align="right" class="l-table-edit-td">虚机IP:</td>
                <td align="left" class="l-table-edit-td" colspan="4">
                	<select style="width: 180px" name="vmid" id="vmid" ltype="select" validate="{required:true}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> >
                	 	<c:forEach items="${vmList}" var="vm">
                	 		<c:choose>
                	 			<c:when test="${command.vm.id eq vm.id}">
                	 				<option value="${vm.id}" selected="selected">${vm.ip}</option>
                	 			</c:when>
                	 			<c:otherwise>
                	 				<option value="${vm.id}">${vm.ip}</option>
                	 			</c:otherwise>
                	 		</c:choose>
                	 	</c:forEach>
                	 </select> 
                </td>
            </tr>
            
            <tr>
                <td align="right" class="l-table-edit-td">开始日期:</td>
                <td align="left" class="l-table-edit-td" colspan="4">
                <c:if test="${viewType!='detail'}">
                	<input name="dateF" type="text" id="dateF" value="${command.dateF}" ltype="date" format="yyyy-MM-dd" validate="{required:true}" />
                </c:if>	
                <c:if test="${viewType=='detail'}">
                	<input type="text" value="${command.dateF}" disabled="disabled" />
                </c:if>	      
                </td>
                  <td align="right" class="l-table-edit-td">结束日期:</td>
                <td align="left" class="l-table-edit-td" colspan="4">
                <c:if test="${viewType!='detail'}">
                	<input name="dateT" type="text" id="dateT" value="${command.dateT}" ltype="date" format="yyyy-MM-dd" validate="{required:true}" />
                </c:if>
                <c:if test="${viewType=='detail'}">
                	<input type="text" value="${command.dateT}" disabled="disabled" />
                </c:if>	           		
                </td>
            </tr> 
        </table>
    </form>
</body>
</html>
